package com.tac.controller;


import com.tac.common.result.Result;
import com.tac.pojo.UserAddress;
import com.tac.service.UserAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RequestMapping("/userAddress")
@RestController()
@CrossOrigin
@Api(value = "用户地址",tags ="用户地址" )
public class UserAddressController {
    @Autowired
    private UserAddressService userAddressService;



    /**
     * 添加地址
     * @param userAddress
     * @return
     */
    @ApiOperation("添加地址")
    @PostMapping("/save")
    public Result save(@RequestBody @Valid UserAddress userAddress){
        return userAddressService.save(userAddress);
    }

    /**
     * 删除地址
     * @param id
     * @param id
     * @return
     */
    @ApiOperation("删除地址")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Integer id){
        return  userAddressService.remove(id);
    }

    /**
     * 按照用户id和地址id修改地址
     * @param userAddress
     * @return
     */
    @ApiOperation("按照用户id和地址id修改地址")
    @PutMapping("/updeteByid")
    public Result updeteByid(@RequestBody UserAddress userAddress){
        return  userAddressService.updeteByid(userAddress);
    }

    /**
     * 按照用户id查询用户地址
     * @param
     * @return
     */
    @ApiOperation("按照用户id查询用户地址")
    @GetMapping("/selectAll")
    public Result<List<UserAddress>> selectAll(){
        return  userAddressService.selectAll();
    }

    /**
     * 设置用户默认地址
     * @return
     */
    @ApiOperation("设置用户默认地址")
    @PutMapping("/updateStaus/{id}")
    public Result updateStaus(@PathVariable Integer id){
        return userAddressService.updateStaus(id);
    }

    /**
     * 按照id查询用户地址
     * @param id
     * @return
     */
    @GetMapping("/selectById")
    @ApiOperation("按照id查询用户地址")
    public Result<UserAddress> selectById(Integer id){
        return userAddressService.selectById(id);
    }
}
